//
//  YZClient+Account.m
//  YZMicroStock
//
//  Created by Lv.Dongdong on 16/4/5.
//  Copyright © 2016年 cqjr. All rights reserved.
//

#import "YZClient+Account.h"

@implementation YZNetworkManager (Account)

- (void)loginForUsername: (NSString *)username
                password: (NSString *)password
                 success:(void (^)(NSURLSessionDataTask *task,id responseObject))success
                 failure: (void (^)(NSError *error))failure {
    
    if (username.length == 0 || password.length == 0) {
        return;
    }

    [self.mainNetwork cq_noCachePOST:URL_FOR_LOGIN parameters:@{@"authencationType":@"AJAX", @"username": username, @"password": password, @"device": @"3"}
                             success:^(NSURLSessionDataTask *task, id responseObject) {
                                 if (success) {
                                     success(task, responseObject);
                                 }
                             } failure:^(NSURLSessionDataTask *task, NSError *error) {
                                 if (failure) {
                                     failure(error);
                                 }
                             }];
}

- (void)sendSmsWithMobile: (NSString *)mobile
                  success:(void (^)(NSURLSessionDataTask *task,id responseObject))success
                  failure: (void (^)(NSError *error))failure
{
    NSDictionary *params = @{@"mobile": mobile,@"device": @"3"};
    
    [self.mainNetwork cq_noCachePOST: URL_FOR_REGAUTH parameters: params
                             success:^(NSURLSessionDataTask *task, id responseObject) {
                                 if (success) {
                                     success(task, responseObject);
                                 }
                             } failure: ^(NSURLSessionDataTask *task, NSError *error) {
                                 if (failure) {
                                     failure(error);
                                 }
                             }];
}

- (void)getMobileAuthCode:(NSString *)mobile
                  success:(void (^)(NSURLSessionDataTask *task,id responseObject))success
                  failure:(void (^)(NSError *error))failure {
    
    NSDictionary *params = @{@"mobile": mobile, @"device": @"3", @"type": @"2"};
    
    [self.mainNetwork cq_noCachePOST: URL_FOR_REGCODE parameters: params
                             success:^(NSURLSessionDataTask *task, id responseObject) {
                                 if (success) {
                                     success(task, responseObject);
                                 }
                             } failure: ^(NSURLSessionDataTask *task, NSError *error) {
                                 if (failure) {
                                     failure(error);
                                 }
                             }];
}

- (void)getMobileAuthCode:(NSString *)mobile withCheckCode:(NSString *)code
                  success:(void (^)(NSURLSessionDataTask *task,id responseObject))success
                  failure:(void (^)(NSError *error))failure {
    
    NSDictionary *params = @{@"mobile": mobile, @"checkCode": code, @"device": @"3"};
    
    [self.mainNetwork cq_noCachePOST: URL_FOR_REGCODE parameters: params
                             success:^(NSURLSessionDataTask *task, id responseObject) {
                                 if (success) {
                                     success(task, responseObject);
                                 }
                             } failure: ^(NSURLSessionDataTask *task, NSError *error) {
                                 if (failure) {
                                     failure(error);
                                 }
                             }];
}


- (void)registerGoNextStepWithMobile:(NSString *)mobile withCheckCode:(NSString *)code
                             Success:(void (^)(NSURLSessionDataTask *task,id responseObject))success
                             failure:(void (^)(NSError *error))failure {
    
    NSDictionary *params = @{COMMON_REQUEST_DEVICE:COMMON_REQUEST_DEVICE_VALUE, @"mobile":mobile, @"checkCode":code};
    
    [self.mainNetwork cq_noCachePOST: URL_FOR_REGISTERCODE_CHECK parameters: params
                             success:^(NSURLSessionDataTask *task, id responseObject) {
                                 if (success) {
                                     success(task, responseObject);
                                 }
                             } failure: ^(NSURLSessionDataTask *task, NSError *error) {
                                 if (failure) {
                                     failure(error);
                                 }
                             }];
}


- (void)registerWithMobile: (NSString *)mobile
                   smsCode: (NSString *)smsCode
                  username: (NSString *)username
                  password: (NSString *)password
                   success:(void (^)(NSURLSessionDataTask *task,id responseObject))success
                   failure: (void (^)(NSError *error))failure {
    
    NSDictionary *params = @{@"device":@"3",
                             @"mobile": mobile,
                             @"checkCode": smsCode,
                             @"password":  password,
                             @"username": username,
                             @"type": @"1"};
    
    [self.mainNetwork cq_noCachePOST: URL_FOR_REGISTER parameters: params
                             success:^(NSURLSessionDataTask *task, id responseObject) {
                                 if (success) {
                                     success(task, responseObject);
                                 }
                             } failure: ^(NSURLSessionDataTask *task, NSError *error) {
                                 if (failure) {
                                     failure(error);
                                 }
                             }];
    
}

- (void)forget_getMobileAuthCode:(NSString *)mobile
                  success:(void (^)(NSURLSessionDataTask *task,id responseObject))success
                  failure:(void (^)(NSError *error))failure {
    
    NSDictionary *params = @{@"mobile": mobile, @"device": @"3", @"type": @"2"};
    
    [self.mainNetwork cq_noCachePOST: URL_FOR_FORGOTPWDGETCODE parameters: params
                             success:^(NSURLSessionDataTask *task, id responseObject) {
                                 if (success) {
                                     success(task, responseObject);
                                 }
                             } failure: ^(NSURLSessionDataTask *task, NSError *error) {
                                 if (failure) {
                                     failure(error);
                                 }
                             }];
}

- (void)forget_getMobileAuthCode:(NSString *)mobile withCheckCode:(NSString *)code
                         success:(void (^)(NSURLSessionDataTask *task,id responseObject))success
                         failure:(void (^)(NSError *error))failure {
    
    NSDictionary *params = @{@"mobile": mobile, @"checkCode":code, @"device": @"3",@"type": @"2"};
    
    [self.mainNetwork cq_noCachePOST: URL_FOR_FORGOTPWDGETCODE parameters: params
                             success:^(NSURLSessionDataTask *task, id responseObject) {
                                 if (success) {
                                     success(task, responseObject);
                                 }
                             } failure: ^(NSURLSessionDataTask *task, NSError *error) {
                                 if (failure) {
                                     failure(error);
                                 }
                             }];
}


- (void)forget_resetPwdWithMobile: (NSString *)mobile andPwd: (NSString *)pwd andCheckCode:(NSString *)checkCode
                          success:(void (^)(NSURLSessionDataTask *task,id responseObject))success
                          failure: (void (^)(NSError *error))failure {
    
    NSDictionary *params = @{@"mobile": mobile, @"password": pwd, @"checkCode": checkCode, @"device": @"3"};
    
    [self.mainNetwork cq_noCachePOST: URL_FOR_FORGOTPWDRESET parameters: params
                             success:^(NSURLSessionDataTask *task, id responseObject) {
                                 if (success) {
                                     success(task, responseObject);
                                 }
                             } failure: ^(NSURLSessionDataTask *task, NSError *error) {
                                 if (failure) {
                                     failure(error);
                                 }
                             }];

}

- (void)keepAliveSuccess:(void (^)(NSURLSessionDataTask *task,id responseObject))success
                 failure: (void (^)(NSError *error))failure {
    
    [self.mainNetwork cq_noCacheGET: URL_FOR_KEEP_ALIVE parameters: @{COMMON_REQUEST_DEVICE:COMMON_REQUEST_DEVICE_VALUE}
                             success:^(NSURLSessionDataTask *task, id responseObject) {
                                 if (success) {
                                     success(task, responseObject);
                                 }
                             } failure: ^(NSURLSessionDataTask *task, NSError *error) {
                                 if (failure) {
                                     failure(error);
                                 }
                             }];
}

- (void)fetchUserAssetsSuccess:(void (^)(NSURLSessionDataTask *task,id responseObject))success
                       failure: (void (^)(NSError *error))failure {
    
    NSDictionary *params = @{@"device": @"3"};
    
    [self.mainNetwork cq_noCachePOST: URL_FOR_FETCH_USER_ASSETS parameters: params
                            success:^(NSURLSessionDataTask *task, id responseObject) {
                                if (success) {
                                    success(task, responseObject);
                                }
                            } failure: ^(NSURLSessionDataTask *task, NSError *error) {
                                if (failure) {
                                    failure(error);
                                }
                            }];

}

- (void)fetchUserDetailSuccess:(void (^)(NSURLSessionDataTask *task,id responseObject))success
                       failure: (void (^)(NSError *error))failure {

    NSDictionary *params = @{@"device": @"3"};
    
    [self.mainNetwork cq_noCachePOST: URL_FOR_FETCH_USER_DETAIL parameters: params
                             success:^(NSURLSessionDataTask *task, id responseObject) {
                                 if (success) {
                                     success(task, responseObject);
                                 }
                             } failure: ^(NSURLSessionDataTask *task, NSError *error) {
                                 if (failure) {
                                     failure(error);
                                 }
                             }];


}

- (void)resetLoginPwdWithOldPwd: (NSString *)oldPwd andNewPwd: (NSString *)newPwd
                   success:(void (^)(NSURLSessionDataTask *task,id responseObject))success
                   failure: (void (^)(NSError *error))failure {

    NSDictionary *params = @{@"oldPassword": oldPwd, @"newPassword": newPwd, @"device": @"3"};
    
    [self.mainNetwork cq_noCachePOST: URL_FOR_RESET_LOGIN_PWD parameters: params
                             success:^(NSURLSessionDataTask *task, id responseObject) {
                                 if (success) {
                                     success(task, responseObject);
                                 }
                             } failure: ^(NSURLSessionDataTask *task, NSError *error) {
                                 if (failure) {
                                     failure(error);
                                 }
                             }];
}

- (void)setDrawPwdWithPwd:(NSString *)pwd
                  success:(void (^)(NSURLSessionDataTask *task,id responseObject))success
                  failure: (void (^)(NSError *error))failure {
    
    NSDictionary *params = @{@"password": pwd, @"device": @"3"};
    
    [self.mainNetwork cq_noCachePOST: URL_FOR_SET_DRAW_PWD parameters: params
                             success:^(NSURLSessionDataTask *task, id responseObject) {
                                 if (success) {
                                     success(task, responseObject);
                                 }
                             } failure: ^(NSURLSessionDataTask *task, NSError *error) {
                                 if (failure) {
                                     failure(error);
                                 }
                             }];
}

- (void)at_updateRealName:(NSString *)name andIDCard:(NSString *)idCard success:(void (^)(NSURLResponse *response,id responseObject))success failure: (void (^)(NSError *error))failure
{
    [self.mainNetwork cq_noCachePOST: URL_FOR_UPDATE_REAL_NAME parameters: @{@"name":name, @"idNumber":idCard, COMMON_REQUEST_DEVICE:COMMON_REQUEST_DEVICE_VALUE}
                             success:^(NSURLSessionDataTask *task, id resObj) {
                                 if (success) {
                                     success(task.response, resObj);
                                 }
                             } failure: ^(NSURLSessionDataTask *operation, NSError *error) {
                                 if (failure) {
                                     failure(error);
                                 }
                             }];
}

- (void)at_verifyIdentifyWithRealName:(NSString *)name andIDCard:(NSString *)idCard andFrontData:(NSData *)frontData andBackData:(NSData *)backData andProfileData:(NSData *)profileData success:(void (^)(NSURLResponse *response,id responseObject))success failure: (void (^)(NSError *error))failure
{
    [self.mainNetwork cq_noCachePOSTData:URL_FOR_UPLOAD_IDCARD parameters:@{@"name":name, @"idNumber":idCard, COMMON_REQUEST_DEVICE:COMMON_REQUEST_DEVICE_VALUE} constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
        [formData appendPartWithFileData:frontData name:@"frontPic" fileName:@"1.jpeg" mimeType:@"image/jpeg"];
        [formData appendPartWithFileData:backData name:@"backPic" fileName:@"2.jpeg" mimeType:@"image/jpeg"];
        [formData appendPartWithFileData:profileData name:@"profilePic" fileName:@"3.jpeg" mimeType:@"image/jpeg"];
    } success:^(NSURLSessionDataTask *task, id resObj) {
        if (success) {
            success(task.response, resObj);
        }
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        if (failure) {
            failure(error);
        }
    }];
}

- (void)changeWithdrawPwdWithOldPwd: (NSString *)oldPwd andNewPwd: (NSString *)newPwd
                            success:(void (^)(NSURLSessionDataTask *task,id responseObject))success
                            failure: (void (^)(NSError *error))failure {
    
    NSDictionary *params = @{@"oldPassword": oldPwd, @"newPassword": newPwd, @"device": @"3"};
    
    [self.mainNetwork cq_noCachePOST:URL_FOR_CHANGE_DRAW_PWD  parameters: params
                             success:^(NSURLSessionDataTask *task, id responseObject) {
                                 if (success) {
                                     success(task, responseObject);
                                 }
                             } failure: ^(NSURLSessionDataTask *task, NSError *error) {
                                 if (failure) {
                                     failure(error);
                                 }
                             }];

}

- (void)forget_getAuthCodeWithVoice:(BOOL)voice
                            success:(void (^)(NSURLSessionDataTask *task,id responseObject))success
                            failure: (void (^)(NSError *error))failure {
    
    NSDictionary *params = @{@"useVoice": @(voice), @"device": @"3"};
    
    [self.mainNetwork cq_noCachePOST:URL_FOR_FORGOT_DRAW_PWD_SEND_CODE  parameters: params
                             success:^(NSURLSessionDataTask *task, id responseObject) {
                                 if (success) {
                                     success(task, responseObject);
                                 }
                             } failure: ^(NSURLSessionDataTask *task, NSError *error) {
                                 if (failure) {
                                     failure(error);
                                 }
                             }];

}

- (void)forget_resetWithdrawPwdWithPwd:(NSString *)pwd andCheckCode:(NSString *)checkCode
                               success:(void (^)(NSURLSessionDataTask *task,id responseObject))success
                               failure: (void (^)(NSError *error))failure {
    
    NSDictionary *params = @{@"password": pwd, @"checkCode": checkCode, @"device": @"3"};
    
    [self.mainNetwork cq_noCachePOST:URL_FOR_FORGOT_DRAW_PWD_SET_NEW  parameters: params
                             success:^(NSURLSessionDataTask *task, id responseObject) {
                                 if (success) {
                                     success(task, responseObject);
                                 }
                             } failure: ^(NSURLSessionDataTask *task, NSError *error) {
                                 if (failure) {
                                     failure(error);
                                 }
                             }];

}

- (void)fetchNoticeListSuccess:(void (^)(NSURLSessionDataTask *task,id responseObject))success
                       failure: (void (^)(NSError *error))failure {
    
    [self.mainNetwork cq_noCacheGET: URL_FOR_FETCH_NOTICE parameters: @{COMMON_REQUEST_DEVICE:COMMON_REQUEST_DEVICE_VALUE}
                            success:^(NSURLSessionDataTask *task, id responseObject) {
                                if (success) {
                                    success(task, responseObject);
                                }
                            } failure: ^(NSURLSessionDataTask *task, NSError *error) {
                                if (failure) {
                                    failure(error);
                                }
                            }];
}

- (void)logoutSuccess:(void (^)(NSURLSessionDataTask *task,id responseObject))success
                       failure: (void (^)(NSError *error))failure {
    
    NSDictionary *params = @{@"device": @"3"};
    
    [self.mainNetwork cq_noCachePOST: URL_FOR_LOGOUT parameters: params
                             success:^(NSURLSessionDataTask *task, id responseObject) {
                                 if (success) {
                                     success(task, responseObject);
                                 }
                             } failure: ^(NSURLSessionDataTask *task, NSError *error) {
                                 if (failure) {
                                     failure(error);
                                 }
                             }];
    
}

- (void)getmystategy:(void (^)(NSURLSessionDataTask *task,id responseObject))success
             failure: (void (^)(NSError *error))failure
{
    [self.mainNetwork cq_noCacheGET: URL_FOR_MYSTRATEGY parameters: @{COMMON_REQUEST_DEVICE:COMMON_REQUEST_DEVICE_VALUE}
                            success:^(NSURLSessionDataTask *task, id responseObject) {
                                if (success) {
                                    success(task, responseObject);
                                }
                            } failure: ^(NSURLSessionDataTask *task, NSError *error) {
                                if (failure) {
                                    failure(error);
                                }
                            }];
}

- (void)payZFAuthWithpayZFAccount:(NSString *)payZFAccount withTradeNo:(NSString *)tradeNo withTradeAmount:(NSString *)tradeAmount
                            Success:(void (^)(NSURLSessionDataTask *task,id responseObject))success
                            failure:(void (^)(NSError *error))failure {
    
    NSDictionary *params = @{COMMON_REQUEST_DEVICE:COMMON_REQUEST_DEVICE_VALUE, @"payZFAccount":payZFAccount, @"tradeNo":tradeNo, @"tradeAmount":tradeAmount};
    
    [self.mainNetwork cq_noCachePOST: [NSString stringWithFormat:@"%@%@",@"user/security/bindingAlip",@"ayAccount.json"] parameters: params
                             success:^(NSURLSessionDataTask *task, id responseObject) {
                                 if (success) {
                                     success(task, responseObject);
                                 }
                             } failure: ^(NSURLSessionDataTask *task, NSError *error) {
                                 if (failure) {
                                     failure(error);
                                 }
                             }];
}

@end
